/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __frstat_thread_output.c                                */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/18 by geyh                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frstat_thread.h"

#include "frstat_module.h"


static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

typedef struct __thread_info {
    unsigned long ul_task_dones;
    unsigned long ul_errors;
    unsigned long ul_requests;
    unsigned long ul_responses;
} Frstat_thread_info;

typedef struct __thread_info_avg {
    unsigned long ul_task_dones[4];
    unsigned long ul_errors[4];
    unsigned long ul_requests[4];
    unsigned long ul_responses[4];
} Frstat_thread_avg;

typedef struct __thread_stat {
    struct timeval start_time; //线程开始时间
    struct timeval run_time; //线程开始时间

    unsigned long int i_thread_id;
    Frstat_thread_info st_thread_total;
    Frstat_thread_avg  st_thread_avg;
} Frstat_thread;

void __frstat_thread_output(Frlist_node* p_node, char *p_outbuff, unsigned int ui_outlen);

void __stat_thread_node_free(Frlist_node* p_node);


static void __case1(void)
{
    Frlist_node* p_node = NULL;
    Frstat_thread *p_stat_thread = NULL;
    char arr_out[1024];

    memset(arr_out, 0x00, sizeof(arr_out));

    p_stat_thread = (Frstat_thread *)frmalloc(sizeof(Frstat_thread));
    memset(p_stat_thread, 0x00, sizeof(Frstat_thread));

    p_stat_thread->st_thread_total.ul_task_dones  = 10;
    p_stat_thread->st_thread_total.ul_errors   = 10;
    p_stat_thread->st_thread_total.ul_requests   = 10;
    p_stat_thread->st_thread_total.ul_responses   = 10;

    p_node = frlist_node_create(p_stat_thread);

    __frstat_thread_output(p_node, arr_out, sizeof(arr_out));
    CU_ASSERT_STRING_EQUAL(arr_out,"id=0, start=1970/01/01 08:00:00, last_update=1970/01/01 08:00:00\n\ttask_dones=10(0/s), errors=10(0/s), requests=10(0/s), responses=10(0/s)\n");

    frdbg("\t%s\n",arr_out);
    __stat_thread_node_free(p_node);
    frfree(p_node);

}


int add_suite___frstat_thread_output(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frstat_thread __frstat_thread_output()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
//    CU_add_test(pSuite, "case2", __case2);
//    CU_add_test(pSuite, "case3", __case3);
//    CU_add_test(pSuite, "case4", __case4);

    return FR_SUCC;
}
